<?php
require_once dirname(__FILE__) . '/inc.head.php';
$cond_vals = new stdClass();
$cond_vals->c = 't.customer_id = :v1 AND is_paid = 1 AND is_cancel = 0';
$cond_vals->v = array(':v1' => $_SESSION['index' . USER]->id);
$opt = new stdClass();
$opt->select_expr = 'SUM(t.total) AS _total';
$total = DbUtils::get($myPdo, TABLE_NAME_PREFIX_PLUGIN . 'ecom_order', $cond_vals, NULL, NULL, NULL, NULL, $opt)->d[0]->_total;
if (!$total) {
  $total = 0;
}
$members = DbUtils::get($myPdo,  TABLE_NAME_PREFIX_PLUGIN . 'ecom_customer_member', NULL, 't.total_spent', 'ASC', NULL, NULL, NULL)->d;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<script src="../../../libs/jquery/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="js/sliding_effect.js"></script>
<style>
* {
  font-family: Trebuchet MS;
  font-size: 12px;
}
table.list {
  border-left: 1px solid #aaa;
  border-top: 1px solid #aaa;
  font-size: 13px;
  width: 100%;
}
table.list th.sort {
  text-align: left;
  height: 28px;
  background-color: #ddd;
  padding: 0 5px; 
  border-right: 1px solid #aaa;
  border-bottom: 1px solid #aaa;
  font-weight: bold;
  vertical-align: middle;
  cursor: pointer;
  color: #333;
  font-size: 13px;
}
table.list tr.rowodd td {
  padding: 0 5px;
  height: 25px;
  background-color: #eee;
  border-right: 1px solid #aaa;
  border-bottom: 1px solid #aaa;
  word-wrap: break-word;
  vertical-align: middle;
  overflow: hidden;
}
table.list tr.roweven td {
  padding: 0 5px;
  height: 25px;
  background-color: #fff;
  border-right: 1px solid #aaa;
  border-bottom: 1px solid #aaa;
  word-wrap: break-word;
  vertical-align: middle;
}
table.list tr.rowodd:hover td {
  background-color: #f4f3b2;
}
table.list tr.roweven:hover td {
  background-color: #f4f3b2;
}
table.list tr.none td {
  padding: 0 5px;
  height: 25px;
  background-color: #fff;
  border-right: 1px solid #666;
  border-bottom: 1px solid #666;
  word-wrap: break-word;
}
table.lo {
  width: 100%;
}
table.lo td {
  vertical-align: top;
}
.imgbtn {
  background-image: url(img/save.png);
  background-repeat: no-repeat;
  background-position: 5px 2px;
  padding: 5px 5px 5px 30px;
  border: 1px solid #666;
  background-color: #fff;
  cursor: pointer;
  border-radius: 3px;
  font-family: Lucida Sans Unicode;
}
.imgbtn:hover {
  background-color: #eee;
}
</style>
</head>
<body>
<table class="lo" cellpadding=0 cellspacing=0>
  <tr>
    <td style="width: 200px;"><?php include dirname(__FILE__) . '/inc.left.php'?></td>
    <td style="padding-left: 20px; padding-top: 18px;">
      <?php if ($unpaid != 0) { ?>
      <div style="padding: 5px;border: 1px solid #ff0000;background: #ffa6a6;">
        <div><b style="font-size: 13px;font-family: Lucida Sans Unicode;">You have <?php echo $unpaid; ?> unpaid orders. Please <a href="#" onclick="parent.location.href='http://<?php echo URL . '?i=' . $page_id . '&script=index_order&status=1'; ?>';">Pay Now</a> or they will be cancelled shortly.</b></div>
        <div>If you are arranging an offline payment, please ignore the message.</div>
      </div>
      <div>&nbsp;</div>
      <?php } ?>
      <table style="border-top: 1px solid #ddd;border-bottom: 1px solid #ddd;" cellpadding=0 cellspacing=0>
        <tr>
          <td style="width: 125px;">
            <div>&nbsp;</div>
            <div style="border: 4px solid #ddd;padding: 15px 10px">
              <div style="text-align: center;">You are <b><?php echo $_SESSION['index' . USER]->_member; ?></b></div>
              <div><b style="font-size: 14px;font-family: Lucida Sans Unicode;">Total Spent:</b></div>
              <div></div><b style="font-size: 18px;color: #ff8000;">$<?php echo $total; ?></b></div>
            </div>
            <div>&nbsp;</div>
          </td>
          <td style="padding: 0 5px;">&nbsp;</td>
          <td style="padding: 0 5px;border-left: 2px solid #ddd;">&nbsp;</td>
          <td>
            <div>&nbsp;</div>
            <b style="font-size: 14px;font-family: Lucida Sans Unicode;">Membership Rules</b>
            <table class="list" cellPadding="0" cellSpacing="0">
              <tr>
                <th class="sort" width="120px">Membership</th>
                <th class="sort" width="240px">If spent more than</th>
              </tr>
              <?php foreach ($members as $idx => &$mb) { ?>
              <tr class="<?php echo (($idx % 2 == 0) ? 'roweven' : 'rowodd'); ?>">
                <td><?php echo $mb->title; ?></td>
                <td>$<?php echo $mb->total_spent; ?></td>
              </tr>
              <?php } ?>
              <?php if (count($members) == 0) { ?>
              <tr class="none" ><td colspan=4>No Results</td></tr>
              <?php } ?>
            </table>
            <div style="color: red;">YOU MAY NEED TO LOGOUT AND LOGIN AGAIN TO UPGRADE</div>
            <ul>
              <li>The amount of money paid on the same account are accumulated in our system</li>
              <li>When the amount reaches a required number, membership of the account will be upgraded automatically </li>
              <li>More advanced grade of membership gets better discounts</li>
              <li>Paid on different accounts can not be added</li>
              <li>Some products or specials may not have discount</li>
              <li>We reserve all our rights and remedies</li>
            </ul>
            <div>&nbsp;</div>
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
</body>
</html>